<#include "overall_header.html">

						<h1><#if se_page.bean.ticket.id == 0>${L("nav.ticketadd")}<#else>${L("nav.ticketedit")}</#if></h1>
						<p> </p>

						<form action="${se_page.post_action}" method="post" id="form_2" enctype="multipart/form-data">

							<table cellspacing="1">
								<colgroup>
									<col width="130" class="col1"><col width="250" class="col2"><col width="130" class="col1"><col class="col2">
								</colgroup>
								<tbody>
									<tr>
										<td>${L("ticket.owner")} *</td>
										<td colspan="3">
											<select id="project_id" name="project_id">
												${se_page.project_options}
											</select>
											<#if se_page.bean.error_msg["project_id"]??><span class="errormsg-inline">${se_page.bean.error_msg["project_id"]}</span></#if>

											<select id="owner_id" name="owner_id">
												${se_page.owner_options}
											</select>
											<#if se_page.bean.error_msg["owner_id"]??><span class="errormsg">${se_page.bean.error_msg["owner_id"]}</span></#if>

											${L("ticket.priority")}: <select id="priority" name="priority">
											${se_page.priority_options}
											</select>
											${L("ticket.status")}: <select id="status" name="status">
											${se_page.status_options}
											</select>
										</td>
									</tr>
									<tr>
										<td>${L("ticket.subject")} *</td>
										<td colspan="3">
											<input type="text" value="${se_page.bean.ticket.subject?html}" size="75" maxlength="160" id="subject" name="subject">
											<#if se_page.bean.error_msg["subject"]??><span class="errormsg-inline">${se_page.bean.error_msg["subject"]}</span></#if>
										</td>
									</tr>
									<tr>
										<td>${L("ticket.content")} *</td>
										<td colspan="3">
											<textarea class="mceEditor" id="ticket_content" name="ticket_content" style="height: 260px; width:600px;">${se_page.bean.ticket.content?html}</textarea>
											<#if se_page.bean.error_msg["ticket_content"]??><span class="errormsg">${se_page.bean.error_msg["ticket_content"]}</span></#if>
										</td>
									</tr>
									<tr>
										<td>${L("ticket.start-date")}</td>
										<td>
											<input type="text" value="<#if se_page.bean.ticket.startDate??>${se_page.bean.ticket.startDate?string('yyyy-MM-dd')}</#if>" size="15" maxlength="15" id="start_date" name="start_date">
											<#if se_page.bean.error_msg["start_date"]??><span class="errormsg">${se_page.bean.error_msg["start_date"]}</span></#if>
										</td>
										<td>${L("ticket.due-date")}</td>
										<td>
											<input type="text" value="<#if se_page.bean.ticket.dueDate??>${se_page.bean.ticket.dueDate?string('yyyy-MM-dd')}</#if>" size="15" maxlength="15" id="due_date" name="due_date">
											<#if se_page.bean.error_msg["due_date"]??><span class="errormsg-inline">${se_page.bean.error_msg["due_date"]}</span></#if>
										</td>
									</tr>
									<tr>
										<td>${L("tag.tags")}</td>
										<td colspan="3">
											<select id="tags" name="tags" multiple>
											${se_page.tag_options}
											</select>
											<#if se_page.bean.error_msg["tags"]??><span class="errormsg-inline">${se_page.bean.error_msg["tags"]}</span></#if>
										</td>
									</tr>
								</tbody>
							</table>

							<div id="dialog-confirm" title="${L("global.confirm")}">
							    <p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>${L("global.confirm-message")}</p>
							</div>
							<div id="dialog-message" title="${L("global.message")}">
							    <p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>${L("global.select-cannot-be-empty")}</p>
							</div>
							<fieldset class="submit-buttons">
								<input type="hidden" name="id" value="${se_page.bean.ticket.id}"/><br/>
								<input type="hidden" name="redirect" value="${se_page.bean.redirect}" />
								<input type="hidden" name="form_submit" value="1"/>
								<input type="submit" value="${L("global.submit")}" name="form_submit" class="button1">
							</fieldset>

							<table cellspacing="1">
								<caption>${L("attachment.attachments")}</caption>
								<colgroup>
									<col width="130" class="col1"><col class="col2">
								</colgroup>
								<tbody>
									<#if se_page.bean.attachments?? && se_page.bean.attachments?size &gt; 0><#list se_page.bean.attachments as attachment>
									<tr>
										<td></td>
										<td>
											<div style="background-color: #EEE; border: 1px solid #CCCFD3; padding:5px; margin: 0 3px 3px 0; float:left;">
											<a href="${sf_configs.file_site_base}${sf_configs.file_for_static}${attachment.path}" target="_blank">
											<#if attachment.type == 1><img src="${sf_configs.file_site_base}${sf_configs.file_for_static}${attachment.path}" border="0" width="150" /><#else><i>${attachment.name}</i></#if>
											</a>
											</div>
											<input type="hidden" name="attachments" value="${attachment.id}"/>
											<input type="submit" class="button2" value="${L("global.delete")}" name="delete_attachment" id="delete_attachment_${attachment.id}">
										</td>
									</tr>
									</#list></#if>
									<tr>
										<td></td>
										<td>
											<input type="file" class="inputbox autowidth" value="" id="fileupload" name="fileupload">
											<input type="submit" class="button2" value="${L("global.add")}" name="add_attachment">
											<#if se_page.bean.error_msg["fileupload"]??><span class="errormsg">${se_page.bean.error_msg["fileupload"]}</span></#if>
										</td>
									</tr>
								</tbody>
							</table>

							<script type="text/javascript">
								$("#dialog-confirm").hide();
								$("#dialog-message").hide();

								$('#start_date').datepicker({ dateFormat: 'yy-mm-dd' });
								$('#due_date').datepicker({ dateFormat: 'yy-mm-dd' });
								tinyMCE.init({
									theme : "advanced",
									theme_advanced_toolbar_location : "top",
									theme_advanced_toolbar_align : "left",
									theme_advanced_buttons3 : "",
									theme_advanced_disable : "image,formatselect,styleselect",
									width:"600",
									mode : "specific_textareas",
									external_image_list_url : "attachmentfortinymce",
									valid_elements : "-code,-pre,address,-h1,-h2,-h3,-h4,-h5,-h6,hr,p,div[id|name|align|style],a[href|target=_blank],strong/b,br,-ul,-li,em/i,u,-table[border=0|cellspacing|cellpadding],-tr,#td,#th,col,colgroup,caption,thead,tbody,img[style|src|alt|width]",
									editor_selector : /(mceEditor)/
								});

								$("#tags").multiselect({
									position: {
										my: 'left bottom', 
										at: 'left top'
									},
									header: false,
									noneSelectedText: '${L("global.please-select")}',
									selectedList: 5,
									height: 300,
									minWidth: 330
								});

								$('#project_id').change(function() {
									var projectId = $('#project_id option:selected').val();
									$.ajax({
										type			: 'GET',
										url			: '${sf_configs.root_path}/json-projectusers${sf_configs.extension}',
										data			: {"project_id":projectId},
										cache		: false,
										dataType	: "json",
										success	: function(data){
											var dropdown = '<option value="0" title="--">--</option>';
											$.each(data, function(i) {
												var selected = (data[i].id == ${se_page.bean.ticket.ownerId}) ? 'selected' : '';
												dropdown +='<option value="'+data[i].id+'" title="'+data[i].name+'" '+selected+'>'+data[i].name+'</option>';
											});
											$('#owner_id').html(dropdown);
										}
									})
								}).change();

								$('input[name="delete_attachment"]').click(function(){
									var id = $(this).attr('id').replace('delete_attachment_', '');
									return delete_confirm(id);
								});

								function delete_confirm(delete_id){
									$("#dialog-confirm").dialog({
							            resizable: false,
							            height:140,
							            modal: true,
							            buttons: {
							                "${L("global.yes")}": function() {
							                	$('#form_2').append('<input type="hidden" name="delete_attachment_id" value="'+delete_id+'" />');
							                    $('#form_2').submit();
							                },
							                "${L("global.no")}": function() {
							                    $( this ).dialog( "close" );
							                }
							            }
							        });
									return false;
								}
							</script>
						</form>

<#include "overall_footer.html">
